<template>
	<div style="height:3000px">
		<!-- 电气设计审核 --页面 -->
		<v-card>
			<v-card-title>


				<v-row class="mt-2">
					<v-col cols="12" md="1">
						<v-btn class="mt-1" small tile color="primary"
							:disabled="checkMechanicalAudit()" @click="mechanicalAuditClick">
							审核
						</v-btn>
					</v-col>
					<v-divider style="height: 50px;" class="mx-4" inset vertical></v-divider>
					<v-col cols="12" md="1">
						<v-text-field label="项目号" v-model="query.projectcode" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" md="1">
						<v-text-field label="项目名称" v-model="query.projectname" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" md="1">
						<v-text-field label="设备名称" v-model="query.equiname" dense outlined>
						</v-text-field>
					</v-col>
					<v-col cols="12" md="1">
						<v-text-field label="名称(零部件外购件配件名称)" v-model="query.partname" dense outlined>
						</v-text-field>
					</v-col>
			<!-- 		<v-col cols="12" md="1">
						<v-text-field label="零件名称" v-model="query.partcommentname" dense outlined>
						</v-text-field>
					</v-col> -->
					<v-col cols="12" md="1">
						<v-select label="审核状态" v-model="query.status" :items="ApprovalStatusItems" dense outlined>
						</v-select>
					</v-col>

					<!-- ml-n16 前面加n是间距 -->
					<!-- class="ml-n16 mx-auto" -->
					<v-col cols="12" md="2">
						<v-btn depressed color="primary" @click="loadPages">查询</v-btn>
						<v-btn class="ml-3" depressed color="primary" @click="refreshLoadPages">
							重置</v-btn>
					</v-col>
				</v-row>
			</v-card-title>
			<v-card-text>
				<v-data-table :headers="processingHeaderList" :items="processingDataList" small fixed-header
					item-key="id" dense show-select class="text-no-wrap" loading-text="正在加载请稍等......"
					:loading="processingLoading" :options.sync="processingOptions" :footer-props="vuetifyDefaultPage"
					:server-items-length="processingTotalCount"  @input="partSelectEvent">
					<template  v-slot:item.approval.approvalstatusname="{ item }">
						<div v-if="item.approval!=null">
						<a v-if="item.approval.approvalstatus==99"
							style="color: #67C23A;">{{item.approval.approvalstatusname}}</a>
						<a v-else-if="item.approval.approvalstatus==-1"
							style="color: red;">{{item.approval.approvalstatusname}}</a>
						<a v-else>{{item.approval.approvalstatusname}}</a>
						</div>
					</template>
					<template v-slot:item.filelengths="{ item }">
						<div>
							<a>{{item.fileInfos.length}}</a>
						</div>
					</template>
					<!-- 母工单展开 -->
				</v-data-table>
			</v-card-text>
		</v-card>
		<auditdialog :ApprovalDialogModel="ApprovalDialogModel" :callBack="loadProcessingList">
		</auditdialog>
	</div>

</template>

<script>
	import audit_dialog from '../components/audit/audit_dialog.vue'
	export default {
		name: 'document_design_audit_electrical',
		components: {
			auditdialog: audit_dialog
		},
		data: () => ({
			query: {
				projectcode: '',
				projectname: '',
				equicode: '',
				equiname: '',
				partname: '',
				partcommentcode: '',
				partcommentname: '',
				status: 1
			},
			ApprovalStatusItems: [],
			processingHeaderList: [],
			partCommentHeaderList: [],
			processingDataList: [],
			processingTotalCount: 0,
			processingLoading: true,
			processingOptions: { //页数
				page: 1,
				//每页行数
				itemsPerPage: 10
			},
			vuetifyDefaultPage: {
				'items-per-page-text': '每页个数',
				'items-per-page-options': [10, 20, 50, 100, 200]
				// 'items-per-page-all-text': '100'
			},
			ApprovalDialogModel: {
				auditEquiDialog: false,
				selectList: [],
				submitUrl: ``,
			},
		}),
		watch: {
			processingOptions: {
				handler() {
					this.loadPages()
				},
				deep: true
			},

		},
		created() {
			this.loadApprovalStatusItems()
			this.loadProcessingHeaderList()
		},
		methods: {
			checkMechanicalAudit() {
				if (this.ApprovalDialogModel.selectList.length <= 0)
					return true
			
				if (this.ApprovalDialogModel.selectList.filter(r => r.approval.approvalstatus == 99|| r.approval.approvalstatus==-1).length > 0)
					return true
			
				return false
			},
			async loadApprovalStatusItems() {

				var response = await this.$httpRequest({
					url: `MES/MESCommon/GetTypes`,
					method: 'post',
					data: ['ApprovalStatus']
				})
				if (response.status == 1) {
					this.ApprovalStatusItems = response.data
				}
			},
			refreshLoadPages() {
				this.query.projectcode = ''
				this.query.projectname = ''
				this.query.equicode = ''
				this.query.equiname = ''
				this.query.partname = ''
				this.query.partcommentcode = ''
				this.query.partcommentname = ''
				this.query.status = null
			},
			async loadPages() {
				await this.loadProcessingList()
			},
			//加载加工件
			async loadProcessingList() {
				this.processingLoading = true
				var response = await this.$httpRequest({
					url: `PDM/PDMDesignAuditMechanical/LoadPartAllList?projectcode=${this.query.projectcode}&projectname=${this.query.projectname}&equiname=${this.query.equiname}&partname=${this.query.partname}&status=${this.query.status}&approvalCategoryType=5&pageNumber=${this.processingOptions.page}&pageSize=${this.processingOptions.itemsPerPage}`,
					method: 'get',
				})
				if (response.status == 1) {
					this.processingDataList = response.data.result
					this.processingTotalCount = response.data.pagination.totalRecords
					this.processingLoading = false
				} else {
					this.$message.error(response.info)
				}
			},
			partSelectEvent(items) {
				this.ApprovalDialogModel.selectList = items
				console.log(items)
			},
			//机械设计审核
			mechanicalAuditClick() {
				this.ApprovalDialogModel.auditEquiDialog = true
				this.ApprovalDialogModel.submitUrl = `PDM/PDMDesignAuditMechanical/AuditPart`
			},

			//加工件头信息
			loadProcessingHeaderList() {
				this.processingHeaderList = [
					{
						text: '审批状态',
						align: 'center',
						value: 'approval.approvalstatusname',
						filterable: false,
						class: 'fixed'
					},
					{
						text: '图号',
						value: 'piccode',
						align: 'center',
						filterable: true,
					},
					{
						text: '名称',
						value: 'name',
						align: 'center',
						filterable: true,
					},
					{
						text: '结构',
						value: 'keypathname',
						align: 'left',
						filterable: true,
					},
					{
						text: '类型',
						value: 'bomtypename',
						align: 'center',
						filterable: true,
					},
					{
						text: '大类别',
						value: 'bomchildrentypename',
						align: 'center',
						filterable: true,
					},
					{
						text: '设备名称',
						value: 'equipment.name',
						align: 'center',
						filterable: true,
					},
					{
						text: '实际用料名称',
						value: 'real_material_name',
						align: 'center',
						filterable: true,
					},
					{
						text: '实际用料数量',
						value: 'real_material_qty',
						align: 'center',
						filterable: true,
					},
					{
						text: '实际用料单位',
						value: 'real_material_unit',
						align: 'center',
						filterable: true,
					},
					{
						text: '实际用料规格型号',
						value: 'real_material_specifications',
						align: 'center',
						filterable: true,
					},
					{
						text: '机台号',
						value: 'machinecode',
						align: 'center',
						filterable: true,
					},
					{
						text: '表面处理',
						value: 'surface_treatment',
						align: 'center',
						filterable: true,
					},
					{
						text: '外购件供应商名称',
						value: 'suppliername',
						align: 'center',
						filterable: true,
					},
					{
						text: '外购件建议订货日期',
						value: 'buymaterialdate',
						align: 'center',
						filterable: true,
					},
					{
						text: '装配需求日',
						value: 'assemblydate',
						align: 'center',
						filterable: true,
					},
					{
						text: '设计人员名称',
						value: 'design_username',
						align: 'center',
						filterable: true,
					},
					
					{
						text: '项目名称',
						value: 'project.citemname',
						align: 'center',
						filterable: true,
					},
					{
						text: '项目号',
						value: 'project.citemcode',
						align: 'center',
						filterable: true,
					},
					{
						text: '审批人回复',
						align: 'left',
						value: 'approval.approvaldescription',
						filterable: false,
						class: 'fixed'
					},
				]
			},

		}
	}
</script>
